package com.test.ssh.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.test.ssh.entity.User;
import com.test.ssh.service.UserService;

public class UserAction extends ActionSupport implements ModelDriven<User>{

	private User user = new User();
	private UserService userService;
	
	public String test() throws Exception {
		
		System.out.println("struts2 is ok!");
		
		return "success";
	}
	
	
	public void printUs() {
		System.out.println(userService);
	}
	
	
	public String login() throws Exception{
		
		User u = userService.getUserByCodePassword(user);
		ActionContext.getContext().getSession().put("user", u);
		
		return "toHome";
	}
	

	public void setUserService(UserService userService) {
		this.userService = userService;
	}


	@Override
	public User getModel() {
		return user;
	}

	
}
